import http from '/src/utils/request'

export function login(data) {
  return http.get(`/oauth/token?grant_type=${data.grant_type}&scope=${data.scope}&client_id=${data.client_id}&client_secret=${data.client_secret}&username=${data.username}&password=${data.password}`)
}

export function register(data) {
  return http.post('/user/register', data)
}

export function getNewestInfo() {
  return http.get('/api/user/info')
}

export function getUserInfo(uid) {
  return http.get('/plugins/baliServer-module-person-information/api/information/' + uid)
}

export function getUserInfoDigest(uid) {
  return http.get('/api/user?current=1&size=5&userId=' + uid)
}

export function isExist(type, value) {
  return http.get(`/user/exist?type=${type}&value=${value}`)
}

export function updateInfos(infos) {
  return http.put('/plugins/baliServer-module-person-information/api/information/', infos)
}

export function uploadAvatar(file) {
  const param = new FormData() // 创建form对象 blob格式
  param.append('file', file) // 通过append向form对象添加数据
  const config = {
    headers: { 'Content-Type': 'multipart/form-data' },
  }
  return http.post('file/avatar', param, config)
}

// 获取用户的通知
export function getNotice(current,size,uid) {
  return http.get(`/plugins/baliServer-module-notification/api/notification?current=${current}&size=${size}&userId=${uid}`)
}

// 读取通知
export function readNotice(id) {
  return http.put('/notice/' + id)
}
export function doSignin(data) {
  return http.post('/plugins/baliServer-module-sign/api/sign/attendance',data)
}
export function hasSignin(data) {
  return http.get('/plugins/baliServer-module-sign/api/sign/attendance/has',data)
}
